/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nonequidistant.FEMSolver1D;

import Integration.IFunction1D;
import nonequidistant.FEMShapeFunctions1D.FEMShapeFunction1D1Pow;

/**
 *
 * @author mark_o
 */
public class StatMatrixGenerator{
    FEMShapeFunction1D1Pow f1;
    FEMShapeFunction1D1Pow f2;
    double a;
    double b;
    double left;
    double right;
    double h;

    public StatMatrixGenerator() {
    }

    public void setLeft(double left) {
        this.left = left;
    }

    public void setRight(double right) {
        this.right = right;
    }

    public void setF1(IFunction1D f1) {
        this.f1 = (FEMShapeFunction1D1Pow) f1;
    }

    public void setF2(IFunction1D f2) {
        this.f2 = (FEMShapeFunction1D1Pow) f2;
        getAB();
    }

    private void getAB(){
        h = Math.abs(f2.getXi() - f1.getXi());
//            a = Math.max(f1.getXi()-f1.gethLeft(), f2.getXi()-f2.gethLeft());
//            a = Math.max(a, left);
//            b = Math.min(f1.getXi()+f1.gethRight(), f2.getXi()+f2.gethRight());
//            b = Math.min(right, b);
    }

    public double[][] getKe(IFunction1D p) {
        double pE = p.calculate(0);

        return new double[][]{
                    {pE/h, -pE/h },
                    {-pE/h, pE/h }
        };
    }

    public double[][] getMe(IFunction1D q) {
        double qE = q.calculate(0);

        return new double[][]{
                    {qE*h/3.0, -qE*h/6.0 },
                    {-qE*h/6.0, qE*h/3.0 }
        };
    }

    public double[][] getAdv(IFunction1D w) {
        double wE = w.calculate(0);
        double xi = f1.getXi();
        double xi1 = f2.getXi();

        return new double[][]{
                    {wE*xi/h, -wE*xi1/h },
                    {-wE*xi/h, wE*xi1/h }
        };
    }

    public double[] getFe(IFunction1D f) {
        double fE = f.calculate(0);
        return new double[]{
                    fE*h/2.0, fE*h/2.0
        };
    }

    public double[][] getAll(IFunction1D p,IFunction1D q,IFunction1D w){
        double pE = p.calculate(0);
        double qE = q.calculate(0);
        double wE = w.calculate(0);
        double xi = f1.getXi();
        double xi1 = f2.getXi();

        return new double[][]{
                    {pE/h + qE*h/3.0 - wE/2.0, -pE/h - qE*h/6.0 + wE/2.0  },
                    {-pE/h - qE*h/6.0 - wE/2.0, pE/h + qE*h/3.0 + wE/2.0}
        };

//        {,  },
//                    {,  }
    }

}
